package com.qkm.xinguan.repository.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qkm.xinguan.domain.entity.HouseInfo;
import com.qkm.xinguan.domain.entity.Order;
import com.qkm.xinguan.domain.infrastructure.mapper.OrderMapper;
import com.qkm.xinguan.domain.transform.dto.HouseInfoDTO;
import com.qkm.xinguan.exception.BusinessException;
import com.qkm.xinguan.repository.OrderRepository;
import com.qkm.xinguan.response.Result;
import com.qkm.xinguan.response.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service
public class OrderRepositoryImpl extends ServiceImpl<OrderMapper, Order> implements OrderRepository {

	@Override
	public Result getAllOrderById(Long id) {
		int b=this.baseMapper.ifExist(id);
		if(b>0){
			List<String> orderIds=this.baseMapper.getTouristById(id);
			// 根据 id列表查询订单
			List<HouseInfo> orders = this.baseMapper.getHouseInfoByIds(orderIds);
			return Result.ok().data(orders) ;
		}else {
			throw new BusinessException(ResultCode.ADD_ORDER_INFO.getCode(), "没有订单，请前往主页订购");
		}

	}

	@Override
	public boolean deleteByHouseId(Long tourist, Long houseId) {
		return this.baseMapper.deleteByHouseId(tourist,houseId);
	}

	@Override
	public boolean clearOrder(Long tourist) {
		return this.baseMapper.clearOrder(tourist);
	}
}
